<template>
	<view class="RushTo-buy">
		<view class="RushTo_main">
			<view class="RushToList">
				<view class="RushToImage" :style="{'background-image':'url('+getImage(info.title_image)+')'}">
					<!-- <image :src="getImage(info.title_image)" mode=""></image> -->
				</view>
				<view class="RushTo_R">
					<view class="RushToNameBox">
						<view class="RushToName">{{info.name}}</view>
						<view class="RushToPrice">￥{{info.money}}</view>
					</view>
					<view class="RushToDays">
						<view class="days">周一至周日</view>
						<view class="days">免预约</view>
					</view>
					<view class="quantityBox">
						<view class="DiscountBox">
							<view class="Discount">随时退</view>
							<view class="Discount">过期自动退</view>
							<view class="Discount">到店</view>
						</view>
						<view class="numberBox">
							<view :class="[orderNum>1?'increase':'reduce']" @click="reduceBtn">-</view>
							<input class="orderNum" type="text" v-model="orderNum"/>
							<view class="increase" @click="increaseBtn">+</view>
						</view>
					</view>
				</view>
			</view>
			<view class="TotalNumBox">
				<view class="TotalName">总价</view>
				<view class="price">￥{{TotalPrice}}</view>
			</view>
			<u-toast ref="uToast" />
		</view>
		<view class="SubmitBtn" @click="topayment">提交订单</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				orderNum:1,
				UnitPrice:165,
				info:{}
			}
		},
		// 监听价格变化
		computed:{
			TotalPrice:function(){
				return this.orderNum * Number(this.info.money);
			}
		},
		onLoad() {
      // #ifdef APP-PLUS
      var args = plus.runtime.arguments;
      if(args){
        app.$vm.setShareDetail(args);
      }
      // #endif
			this.info = uni.getStorageSync("buyData");
		},
		methods: {
			getImage(url){
				if(url&&(url.indexOf("http://")!=-1||url.indexOf("https://")!=-1)){
					return url;
				}else{
					return app.$vm.globalData.imgBaseUrl + url;
				}
			},
			topayment(){
				let obj = {};
				obj.shop_package_id = this.info.id;
				obj.num = this.orderNum;
				console.log(app.$vm.globalData.tgid,this.info.id,app.$vm.globalData.mdid,this.info.shopObj.shop_id,app.$vm.globalData.shareid)
				if((app.$vm.globalData.tgid==this.info.id||app.$vm.globalData.mdid==this.info.shopObj.shop_id)&&app.$vm.globalData.shareid){
					obj.share_user_id = app.$vm.globalData.shareid;
				}
				obj.info = this.info;
				obj.totalPrice = this.TotalPrice;
				uni.setStorageSync("paymentData",obj);
				uni.navigateTo({
					url:"/pages/pagefour/pages/payment/payment"
				})
			},
			reduceBtn(){
				if(this.orderNum>1){
					this.orderNum--
				}else{
					this.$refs.uToast.show({
						title: '至少一件商品',
						type: 'error',
						position:"top"
					})
				}
			},
			increaseBtn(){
				if(this.info.use_num==0){
					if(this.orderNum>=this.info.stock_num){
						this.orderNum = this.info.stock_num;
						this.$refs.uToast.show({
							title:"仅剩"+this.info.stock_num+"份啦",
							type:"error",
							duration:2000
						})
						return false;
					}else{
						this.orderNum++
					}
				}else{
					if(this.orderNum>=this.info.stock_num){
						this.orderNum = this.info.stock_num;
						this.$refs.uToast.show({
							title:"仅剩"+this.info.stock_num+"份啦",
							type:"error",
							duration:2000
						})
						return false;
					}else{
						if(this.orderNum>=this.info.use_num){
							this.$refs.uToast.show({
								title:"每人仅限购买"+this.info.use_num+"份",
								type:"error",
								duration:2000
							})
							return false;
						}else{
							this.orderNum++
						}
					}
				}
			}
		}
	}
</script>

<style scoped>
.RushTo-buy{
	background: #F3F3F3;
	height: 100vh;
	overflow: auto;
	/* padding-top: 120upx; */
}
.RushTo_main{
	margin-top: 16upx;
}
.RushToList{
	display: flex;
	width: 750upx;
	height: 144upx;
	background: #FFFFFF;
	opacity: 1;
	padding: 24upx;
	box-sizing: border-box;
}
.RushToImage{
	width: 96upx;
	height: 96upx;
	opacity: 1;
	border-radius: 8upx;
	overflow: hidden;
	background-position: center;
	background-size: cover;
}
.RushToImage>image{
	width: 100%;
	height: 100%;
}
.RushTo_R{
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	width: calc(100% - 96upx);
	height: 100%;
	padding-left: 16upx;
}
.RushToNameBox{
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.RushToName{
	font-size: 24upx;
	font-family: Source Han Sans CN;
	font-weight: 500;
	line-height: 40upx;
	color: #333333;
}
.RushToPrice{
	font-size: 24upx;
	font-family: Source Han Sans CN;
	font-weight: bold;
	line-height: 40upx;
	color: #333333;
}
.RushToDays{
	display: flex;
	align-items: center;
}
.days{
	font-size: 16upx;
	font-family: Source Han Sans CN;
	font-weight: 400;
	line-height: 28upx;
	color: #D0D0D0;
	margin-right: 16upx;
}
.quantityBox{
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.DiscountBox{
	display: flex;
	align-items: center;
}
.Discount{
	font-size: 16upx;
	font-family: Source Han Sans CN;
	font-weight: 400;
	line-height: 28upx;
	color: #D0D0D0;
	margin-right: 16upx;
}
.numberBox{
	display: flex;
	align-items: center;
}
.reduce{
	width: 40upx;
	height: 40upx;
	background: #EEEEEE;
	opacity: 1;
	border-radius: 8upx;
	line-height: 40upx;
	text-align: center;
	color: #fff;
}
.orderNum{
	width: 58upx;
	font-size: 20upx;
	font-family: Source Han Sans CN;
	font-weight: 400;
	line-height: 34upx;
	color: #333333;
	text-align: center;
}
.increase{
	width: 40upx;
	height: 40upx;
	background: #FFAC3F;
	opacity: 1;
	border-radius: 8upx;
	line-height: 40upx;
	text-align: center;
	color: #fff;
}
.TotalNumBox{
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 750upx;
	height: 72upx;
	background: #FFFFFF;
	opacity: 1;
	margin-top: 16upx;
	padding: 24upx;
}
.TotalName{
	font-size: 24upx;
	font-family: Source Han Sans CN;
	font-weight: 400;
	line-height: 40upx;
	color: #333333;
	opacity: 1;
}
.price{
	font-size: 24upx;
	font-family: Source Han Sans CN;
	font-weight: bold;
	line-height: 40upx;
	color: #FFAC3F;
}
.SubmitBtn{
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	width: 750upx;
	height: 100upx;
	background: #FFAC3F;
	opacity: 1;
	font-size: 28upx;
	font-family: Source Han Sans CN;
	font-weight: 400;
	line-height: 100upx;
	text-align: center;
	color: #FFFFFF;
}
</style>
